package section_01.file;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

public class DirList {
	public static void main(String[] args) {
		File path = new File("e:\\javaFile\\");
		String[] list = path.list(new DirFilter("D.*\\.java"));
		for (String dirItem : list) {
			System.out.println(dirItem);
		}
	}
}

class DirFilter implements FilenameFilter {
	private Pattern pattern;

	public DirFilter(String regex) {
		pattern = Pattern.compile(regex);
	}

	public boolean accept(File dir, String name) {

		return pattern.matcher(name).matches();
	}

}
